//
// Worm epidemic model
//
// @author Michael Liljenstam, ISTS, Dartmouth College
//
// $Id: DeterministicWormEpidemic.java,v 1.2 2003/03/03 03:07:54 mili Exp $

package SSF.App.Worm;

import java.util.*;

//.............................................................
/**
 *  Worm Epidemiological model.
 *  Contains epidemic state of the AS.
 */
public class DeterministicWormEpidemic extends WormEpidemic {

    /** Function used to compute removals. */
    GammaFunction gammaFctn = null;

    // -- methods ----------------------------------------------------

    public DeterministicWormEpidemic() {
	// create worm epidemic state objects for each AS according to 
	// this implementation
	int numASs = MacroscopicModel.ref.net.numASs;

	for (int i=0; i < numASs; i++) {
	    AS as = MacroscopicModel.ref.net.ases[i];
	    as.wormModel = new DeterministicWormEpidemicState(as);
	}
    }

    /**
     *  Create and set the gamma function.
     */
    public void setGammaFunction(String gammaClass) {
	try {
	    Class gclass = Class.forName(gammaClass);
	    Object gobj = gclass.newInstance();
	    gammaFctn = (GammaFunction) gobj;
	} catch (Exception any) {
	    System.err.println("Can't use GammaFunction "+gammaClass+":");
	    any.printStackTrace();
	}
    }


    /**
     *  One global timestep.
     */
    public void update() {
	ASGraph asGraph = MacroscopicModel.ref.net;

	// sum total infected right now
	iTot = 0;
	for (int j = 0; j < asGraph.numASs; j++) {
	    iTot += asGraph.ases[j].wormModel.i;
	}

	// update each AS state with next timestep
	for (int j = 0; j < asGraph.numASs; j++) {
	    asGraph.ases[j].wormModel.update(iTot);
	}
    }

    public void output() {
	//	System.out.print("  " + s + "  " + i + "  " + r);
    }


} // class DeterministicWormEpidemic


